package logic

import (
	"context"
	"taobao/goods_srv/model/mysql"

	"taobao/goods_srv/internal/svc"
	"taobao/goods_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLogLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogLogic {
	return &UserLogLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserLogLogic) UserLog(in *user.UserLoginRequest) (*user.UserIdResponse, error) {
	// todo: 用户登录

	u := mysql.UserWeek{}

	err := u.LoginByUsernamePwd(in.Username, in.Password)
	if err != nil {
		logx.Error("查询失败", err)
		return nil, err
	}

	return &user.UserIdResponse{
		UserId: int64(u.ID),
	}, nil
}
